<!DOCTYPE html>

<html>

<head>
    <meta charset="utf-8">
    <title>异常登记</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="../../layuiadmin/layui/css/my.css" media="all">
</head>

<body>
    <div style="position:absolute;top:5%;left:5%;height:80%">
        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">发生时间</label>
                    <div class="layui-input-inline">
                        <input id="pdate" type="text" name="pdate" placeholder="请选择时间" class="layui-input">
                    </div>
                    <label class="layui-form-label">异常类型</label>
                    <div class="layui-input-inline">
                        <select name="type">
                            <option value=""></option>
                            <option value="0">遗失</option>
                            <option value="1">泄露</option>
                            <option value="2">破损</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-inline">
                    <label class="layui-form-label">条码</label>
                    <div class="layui-input-inline">
                        <input id="sno" type="text" name="sno" placeholder="请输入条码" autocomplete="off" class="layui-input">
                    </div>
                    <label class="layui-form-label">回收人</label>
                    <div class="layui-input-inline">
                        <select name="cname" id="cname">
                           <option value=""></option>
                       </select>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">异常描述</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入描述" id='context' name='context' class="layui-textarea"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn " lay-submit lay-filter="add" style="background-color:#1E9FFF;">登记</button>
                    <button class="layui-btn layui-btn-primary" id="close">取消</button>
                </div>
            </div>
        </div>
    </div>
    <script src="../../layuiadmin/layui/layui.js"></script>
    <script src="../../layuiadmin/layui/jquery-3.3.1.min.js"></script>
    <script>
        var cwhd = false;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'user'], function() {
            var $ = layui.$,
                setter = layui.setter,
                admin = layui.admin,
                form = layui.form,
                router = layui.router(),
                search = router.search;
            form.render();
            //提交
            layui.use('laydate', function() {
                var laydate = layui.laydate;
                //执行一个laydate实例
                laydate.render({
                    elem: '#pdate', //指定元素
                    theme: '#1E9FFF'
                });

            });
            //
            form.on('submit(add)', function(obj) {
                layer.confirm('是否执行', function(index) {
                    $.ajax({
                        url: '../../../Service/saveException',
                        type: "post",
                        datatype: "json",
                        data: obj.field,
                        success: function(res) {
                            if (res.data == 'ok') {
                                layer.msg('执行成功', {
                                    offset: 'auto',
                                    icon: 1,
                                    time: 1500,
                                    end: function() {
                                        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                                        parent.layer.close(index); // 关闭layer
                                        $("#f5", parent.document).click();
                                    }
                                })
                            } else if (res == '无权限') {
                                layer.msg('没有权限，执行失败', {
                                    offset: 'auto',
                                    icon: 2,
                                    time: 1000
                                })
                            } else {
                                layer.msg('执行失败', {
                                    offset: 'auto',
                                    icon: 2,
                                    time: 1000
                                })
                            }
                        },
                        error: function(res) {
                            layer.msg('执行失败', {
                                offset: 'auto',
                                icon: 2,
                                time: 1000
                            })
                        }
                    })
                })


            });
            $.ajax({
                url: "../../../Employees/select",
                type: "post",
                datatype: "json",
                success: function(res) {
                    $.each(res.data, function(index) {
                        var id = res.data[index].id;
                        var name = res.data[index].name;
                        $("#cname").append("<option value='" + id + "'>" + name + "</option>");
                        form.render();
                    })

                }

            });
            $("#close").on("click", function() {
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index); // 关闭layer
            });
        });
    </script>

</body>

</html>